package mahi.generics;

import java.util.ArrayList;
import java.util.List;

public class Test {
	public static void main(String[] args) {
		//Java 7 Diamond
		Box2<Integer> integerBox = new Box2<>();
		
		
		Box1 rawBox1 = new Box1();  
		
		Box2 rawBox2 = new Box2();  
		
		Box2<Integer> rawBox3 = new Box2<>();
		Box2<String> rawBox4 = new Box2<>();
		
		Box2 box5 = rawBox3;
		box5.set("dsfsad");
		System.out.println(box5.get());
		
		Box2 box6 = rawBox4;
		box6.set(8);
		System.out.println(box6.get());
		
//		Box2 box7 = rawBox1; compile time error
		
		
		List<Box2<String>> lst = new ArrayList<Box2<String>>();
		lst.add(box5);
//		lst.add(box6);  //Run time error
		
		for(Box2<String> box : lst)
		{
			System.out.println(box.get());
		}
		
		
		
		Box2<Integer> rawBoxA = new Box2<>();
		rawBoxA.set(2);
		rawBoxA.inspect(new Long(20));
		
		
		
		
		Box2<Number> box = new Box2<Number>();
		box.add(new Integer(10));   // OK
		box.add(new Double(10.1));  // OK
		//box.add("");  // Not OK
		
		
		//Box<Integer> is not a subtype of Box<Number> even though Integer is a subtype of Number.
		//Note: Given two concrete types A and B (for example, Number and Integer), MyClass<A> has no relationship 
		//to MyClass<B>, regardless of whether or not A and B are related. The common parent of MyClass<A> 
		//and MyClass<B> is Object.
		
	}
}


//if you assign a raw type to a parameterized type, you get a warning:
//warning if you use a raw type to invoke generic methods defined in the corresponding generic type